package com.dw.etl.core.service;
import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlDmtbService;
import com.dw.etl.core.mapper.EtlDmtbMapper;
import com.dw.etl.core.bean.model.EtlDmtb;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * etlDmtb服务实现类
 * Created by hozeData on 2021/07/13.
 */
@Service
@Transactional
public class EtlDmtbServiceImpl implements EtlDmtbService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlDmtbServiceImpl.class);

    @Autowired
    private EtlDmtbMapper etlDmtbMapper;

    @Override
    public int insert(EtlDmtb etlDmtb) {
        if(StringUtils.isEmpty(etlDmtb.getIdDmtb())){
            String uuid32 = UUIDUtil.getUUID32();
            etlDmtb.setIdDmtb(uuid32);
        }
        return etlDmtbMapper.insert(etlDmtb);
    }

    @Override
    public int insertSelective(EtlDmtb etlDmtb)  {
        if(StringUtils.isEmpty(etlDmtb.getIdDmtb())){
            String uuid32 = UUIDUtil.getUUID32();
            etlDmtb.setIdDmtb(uuid32);
        }
        return etlDmtbMapper.insertSelective(etlDmtb);
    }

    @Override
    public int deleteById(String idDmtb)  {
        return etlDmtbMapper.deleteByPrimaryKey(idDmtb);
    }

    @Override
    public int updateByIdSelective(EtlDmtb etlDmtb)  {

        return etlDmtbMapper.updateByPrimaryKeySelective(etlDmtb);
    }

    @Override
    public int updateById(EtlDmtb etlDmtb)  {
        return etlDmtbMapper.updateByPrimaryKey(etlDmtb);
    }

    @Override
    public EtlDmtb getById(String idDmtb)  {
        return etlDmtbMapper.selectByPrimaryKey(idDmtb);
    }

    @Override
    public List<EtlDmtb> findByModel(EtlDmtb etlDmtb)  {
        return etlDmtbMapper.findByModel(etlDmtb);
    }

    @Override
    public PaginationVO<EtlDmtb> findPageByModel(EtlDmtb etlDmtb, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlDmtb> quesList = etlDmtbMapper.findByModel(etlDmtb);
        PageInfo<EtlDmtb> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlDmtb> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
